/**
 * 
 */
package us.gaaoc.framework.manager;


import java.util.List;

import us.gaaoc.framework.dao.ModelFacade;
import us.gaaoc.framework.dao.ModelFacadeHibernate;
import us.gaaoc.framework.model.Roles;
import us.gaaoc.framework.webapp.backingbeans.profile.Links;
import us.gaaoc.framework.webapp.backingbeans.profile.Menu;

/**
 * This Class nvaigation flow depending on the Role of the User
 * @author Sukahda Tapshalkar
 * Sep 5, 2006
 */
public class RoleManager {

	/**
	 * Properties
	 */
	private boolean multicourt;
	private ModelFacade modelFacade;
	private List<Roles> allRoles;
	
	/**
	 * Constructor
	 *
	 */
	public RoleManager(boolean multicourt) {		
		this.multicourt = multicourt;
		this.modelFacade = ModelFacadeHibernate.getInstance();
	}
	
	/**
	 * This method returns the Tab Menu depending on the role of the Person
	 * @param personRoles
	 * @return
	 */
	public Menu manageTabForUser(String courtName,List<Roles> personRoles){
		
		Menu menu = new Menu(courtName);
		
		// personRole= admin
		for (Roles r : personRoles){
			if(r.getRole().contains("admin")){				
				Menu tabMenu = new Menu(courtName);
				tabMenu.getMenu().add(new Links("adminHome", "Home"));
				tabMenu.getMenu().add(new Links("adminConsole", "Admin"));
				if(multicourt) tabMenu.getMenu().add(new Links("chooseCourt","Change Court"));				
				//tabMenu.getMenu().add(new Links("My Profile", "Report Error"));
				
				menu = tabMenu;
				break;								
			}
			
//			personRole = agent
			else if (r.getRole().equals("agent")){
				Menu tabMenu = new Menu(courtName);
				tabMenu.getMenu().add(new Links("agentHome", "Home"));
				tabMenu.getMenu().add(new Links("createNewFilingPage", "New Case"));
				tabMenu.getMenu().add(new Links("viewProfile", "My Profile"));	
				tabMenu.getMenu().add(new Links("help", "Help"));
				if(multicourt) tabMenu.getMenu().add(new Links("chooseCourt","Change Court"));
				menu = tabMenu;
			}
//			personRole = attorney
			else if (r.getRole().equals("attorney")){
				Menu tabMenu = new Menu(courtName);
				tabMenu.getMenu().add(new Links("attorneyHome", "Home"));
				tabMenu.getMenu().add(new Links("viewProfile", "My Profile"));	
				tabMenu.getMenu().add(new Links("help", "Help"));
				if(multicourt) tabMenu.getMenu().add(new Links("chooseCourt","Change Court"));
				menu = tabMenu;
			}
			
			// personRole = clerk
			else if(r.getRole().contains("clerk")){
				Menu tabMenu = new Menu(courtName);
				tabMenu.getMenu().add(new Links("clerkHome", "Home"));
				if(multicourt) tabMenu.getMenu().add(new Links("chooseCourt","Change Court"));
				tabMenu.getMenu().add(new Links("viewProfile", "My Profile"));
				tabMenu.getMenu().add(new Links("help", "Help"));
				menu = tabMenu;
			}
			// personRole = public
			else if (r.getRole().equals("public")){
				Menu tabMenu = new Menu(courtName);
				tabMenu.getMenu().add(new Links("publicHome", "Home"));
				if(multicourt) tabMenu.getMenu().add(new Links("chooseCourt","Change Court"));
				tabMenu.getMenu().add(new Links("viewProfile", "My Profile"));				
				menu = tabMenu;
			}
			//personRole = judge
			else if (r.getRole().equals("judge")){
				Menu tabMenu = new Menu(courtName);
				tabMenu.getMenu().add(new Links("judgeHome", "Home"));
				if(multicourt) tabMenu.getMenu().add(new Links("chooseCourt","Change Court"));
				tabMenu.getMenu().add(new Links("viewProfile", "My Profile"));				
				menu = tabMenu;
			}

		}
		return menu;
	}

	/**
	 * Getter for property allRoles
	 * @return
	 */
	public List<Roles> getAllRoles() {
		this.allRoles = this.modelFacade.findAllRoles();
		return allRoles;
	}

	/**
	 * Setter for property allRoles
	 * @param allRoles
	 */
	public void setAllRoles(List<Roles> allRoles) {
		this.allRoles = allRoles;
	}
}
